package com.aaa.sbms.dao;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @FileName:EResult
 * @Description:
 * @Author :99728
 * @Date: 2020/6/18 17:10
 * @Version:1.0.0
 */

public interface TrainResultDao {
    /**
     * 带参分页查询
     * @param map
     * @return
     */
    @Select("<script>select users.userid,users.username,trainer.trainername,co.coursename,videograde,examgrad,gradetype\n" +
            "from train join users on users.userid=train.userid \n" +
            "join course co on co.courseid=train.courseid \n" +
            "join trainer on trainer.trainerid=train.trainerid \n " +
            " <where>" +
            "<if test=\"coursename!=null\"> and co.coursename like concat('%',#{coursename},'%')</if>" +
            " <if test=\"userid!=null and userid !=''\"> and users.userid =#{userid} </if>"+
            "</where> order by users.userid"+
            " limit #{begin},#{pageSize}</script>")
    List<Map> getPage(Map map);

    /**
     * 带参总条数查询
     */
    @Select("<script>select count(*)" +
            "from train join users on users.userid=train.userid \n" +
            "join course co on co.courseid=train.courseid \n" +
            "join trainer on trainer.trainerid=train.trainerid \n " +
            "<where>" +
            "<if test=\"coursename!=null\"> and co.coursename like concat('%',#{coursename},'%')</if>" +
            " <if test=\"userid!=null and userid !=''\"> and users.userid =#{userid} </if>"+
            "</where></script>")
    int getPageCount(Map map);

    @Select("select * from train where userid = #{userid}")
    Map onelist(int userid);

    /**
     * 更新
     * @param map
     * @return
     */
    @Update("update train set examgrad=#{examgrad} where userid=#{userid}")
    int update(Map map);

    /**
     * 更新
     * @param map
     * @return
     */
    @Update("<script>update train set" +
            "<if test=\"examgrad &gt;=60 \"> gradetype=1</if> " +
            "<if test=\"examgrad &lt; 60 \"> gradetype=0</if>" +
            "where userid=#{userid}</script>")
    int updateA(Map map);
}
